package com.tcgroup.phone.base_core.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;

import androidx.appcompat.widget.AppCompatEditText;

import com.tcgroup.phone.base_core.R;

/**
 * 作者: wangfei
 * 创建时期: 2020/3/25.
 * 包名: com.tcgroup.phone.base_core.widget
 * 类名: OSAndroidMvvm
 */
public class SmartTextInputEditText extends AppCompatEditText {


    private Drawable drawableLeft = null, drawableTop = null, drawableRight = null,
            drawableBottom = null;
    private int drawableWidth, drawableHeight;


    public SmartTextInputEditText(Context context) {
        super(context);
    }

    public SmartTextInputEditText(Context context, AttributeSet attrs) {
        super(context, attrs,0);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SmartDrawableTextView);
        int count = typedArray.getIndexCount();
        for(int i = 0; i < count; i++){
            int attr = typedArray.getIndex(i);
            if (attr == R.styleable.SmartDrawableTextView_smartdrawableRight) {
                drawableRight = typedArray.getDrawable(attr);
            } else if (attr == R.styleable.SmartDrawableTextView_smartdrawableLeft) {
                drawableLeft = typedArray.getDrawable(attr);
            } else if (attr == R.styleable.SmartDrawableTextView_smartdrawableTop) {
                drawableTop = typedArray.getDrawable(attr);
            } else if (attr == R.styleable.SmartDrawableTextView_smartdrawableBottom) {
                drawableBottom = typedArray.getDrawable(attr);
            } else if (attr == R.styleable.SmartDrawableTextView_smartdrawableWidth) {
                drawableWidth = typedArray.getDimensionPixelSize(attr, 0);
            } else if (attr == R.styleable.SmartDrawableTextView_smartdrawableHeight) {
                drawableHeight = typedArray.getDimensionPixelSize(attr, 0);
            }
        }
        if(null != drawableLeft){
            drawableLeft.setBounds(0,0, drawableWidth, drawableHeight);
        }
        if(null != drawableRight){
            drawableRight.setBounds(0,0, drawableWidth, drawableHeight);
        }
        if(null != drawableTop){
            drawableTop.setBounds(0,0, drawableWidth, drawableHeight);
        }
        if(null != drawableBottom){
            drawableBottom.setBounds(0,0, drawableWidth, drawableHeight);
        }
        setCompoundDrawables(drawableLeft, drawableTop, drawableRight, drawableBottom);
    }

    public SmartTextInputEditText(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

    }

}
